from tkinter.font import names

t=(1,2,3)
#t[1]=1

t1=(10,20,30,40)
print(t1[:3])

t2=(5,10,15,10)
print(t2.index(10))

t3=(3,1,2)
t3plus=sorted(t3)
print(t3plus)

t4=("a","b")
t5=(1,2)
print(list(zip(t4,t5)))

s={1,2,3}
s.add(4)
print(s)

s1={10,20,30}
s1.remove(20)
print(s1)

s2={1,2}
s3={2,3}
s4=s2.union(s3)
print(s4)

s5={3,4,5}
s6={1,2}
s6.update(s5)
print(s6)

s7={1,2,3}
s8={3,4,5}
print(s7&s8)
print(s7^s8)

s="Python"
print(s[0])
print(s[-1])

s1="Hello World"
print(s1[::-1])

s2="I like Java"
s3= s2.replace("Java", "Python")  # 替换"Java"为"Python"
print(s3)

s4="apple,banana,orange"
s5=s4.split(",")  # 按逗号分割成列表
print(s5)

s6="  hello  "
s7=s6.strip()
print(s7)

fruits=['apple','banana']
fruits.append('orange')
print(fruits)

fruits.insert(0, 'grape')
print(fruits)

fruits.pop()
print(fruits)

print(fruits.index('banana'))

aaa=[3,1,2]
aaa.sort()
print(aaa)


ages= {'张三':20, '李四':17, '王五':22, '赵六':16}
count=0
for age in ages.values():
    if age > 18:
        count+=1
print(count)


students = {'小明':20, '小红':18, '小刚':19, '小丽':18}
# 使用for循环和if语句找到第一个年龄为18的学生名字
first_name= None
for name,age in students.items():
    if age == 18:
        first_name=name
        break
print(first_name)

data = {'name':'张三', 'age':None, 'city':'北京', 'phone':None}
# 使用while循环和pop()方法删除所有值为None的项
while True:
    none=False
    for key in data.keys():
        if data[key] is None:
            data.pop(key)
            none=True
            break
    if not none:
        break
print(data)

numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
even_sum = 0
for num in numbers:
    if num % 2 == 0:
        even_sum += num
print(even_sum)


data = (5, 8, 12, 3, 15, 7)
index = 0
result = None
while index < len(data):
    if data[index] > 10:
        result = data[index]
        break
    index += 1
print(result)


values = (1, -2, 0, 3, -1, 0, 5, -3)
positive_count = 0
negative_count = 0
zero_count = 0
for num in values:
    if num > 0:
        positive_count += 1
    elif num < 0:
        negative_count += 1
    else:
        zero_count += 1
print(f"正数的个数：{positive_count}")
print(f"负数的个数：{negative_count}")
print(f"零的个数：{zero_count}")


set1 = {1, 2, 3, 4, 5}
set2 = {4, 5, 6, 7, 8}
intersection = set1 & set2
if intersection:
    print(f"两个集合的交集为：{intersection}")
    print("交集不为空集")
else:
    print("交集为空集")


numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
while True:
    found_odd = False
    for num in list(numbers):
        if num % 2 != 0:
            numbers.remove(num)
            found_odd = True
            break
    if not found_odd:
        break
print(numbers)


data = {5, 8, 12, 3, 7}
has_greater_than_10 = False
for num in data:
    if num > 10:
        has_greater_than_10 = True
        break
if has_greater_than_10:
    print("集合中包含大于10的元素")
else:
    print("集合中不包含大于10的元素")


text = "Hello123!@# World"
letter_count = 0
digit_count = 0
other_count = 0
for char in text:
    if char.isalpha():
        letter_count += 1
    elif char.isdigit():
        digit_count += 1
    else:
        other_count += 1
print(f"字母的个数：{letter_count}")
print(f"数字的个数：{digit_count}")
print(f"其他字符的个数：{other_count}")


s = "abc123def456"
index = 0
first_digit_pos = -1
while index < len(s):
    if s[index].isdigit():
        first_digit_pos = index
        break
    index += 1
print(f"第一个数字的位置是：{first_digit_pos}")


sentence = "I love Python programming very much"
words = sentence.split()
short_words = []
medium_words = []
long_words = []
for word in words:
    length = len(word)
    if 1 <= length <= 3:
        short_words.append(word)
    elif 4 <= length <= 6:
        medium_words.append(word)
    else:
        long_words.append(word)
print(f"短单词(1-3)：{short_words}")
print(f"中单词(4-6)：{medium_words}")
print(f"长单词(7+)：{long_words}")


words = ['hello', '', 'world', '', 'python', '']
while True:
    try:
        words.remove('')
    except ValueError:
        break
print(words)


numbers = [23, 45, 12, 67, 89, 34, 56, 78]
first_max = second_max = third_max = 0
for num in numbers:
    if num > first_max:
        third_max = second_max
        second_max = first_max
        first_max = num
    elif num > second_max:
        third_max = second_max
        second_max = num
    elif num > third_max:
        third_max = num
print(f"最大的三个数是：{first_max}, {second_max}, {third_max}")


data = [64, 34, 25, 12, 22, 11, 90]
n = len(data)
for i in range(n):
    for j in range(0, n-i-1):
        if data[j] > data[j+1]:
            data[j], data[j+1] = data[j+1], data[j]
print("排序后的列表：", data)
